package com.shinhye.mobilelottery;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.widget.RelativeLayout;

import com.shinhye.mobilelottery.ui.HallUI;
import com.shinhye.mobilelottery.ui.manager.BottomManager;
import com.shinhye.mobilelottery.ui.manager.MiddleManager;
import com.shinhye.mobilelottery.ui.manager.TitleManager;
import com.shinhye.mobilelottery.utils.PromptManager;

public class MainActivity extends Activity {
//	private Handler handler = new Handler(){
//		public void handleMessage(android.os.Message msg) {
//			mm.changeUI(new SecondUI(MainActivity.this));
//		};
//	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.il_main);
		
		init();
	}

	private void init() {
		DisplayMetrics metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		GlobalParams.windowWidth = metrics.widthPixels;
		
		TitleManager.getInstance().init(this);
		TitleManager.getInstance().changeTitle("中彩网");
		
		BottomManager.getInstance().init(this);
		
		RelativeLayout ii_middle = (RelativeLayout) findViewById(R.id.ii_middle);
		MiddleManager mm = MiddleManager.getInstance();
		mm.setMiddle(ii_middle);
		mm.addObserver(TitleManager.getInstance());
		mm.addObserver(BottomManager.getInstance());
		
		MiddleManager.getInstance().changeUI(HallUI.class, null);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK) {
			boolean goback = MiddleManager.getInstance().goback();
			if(!goback) {
				PromptManager.showExitSystem(this);
//				Toast.makeText(this, "不要退出啊", Toast.LENGTH_SHORT).show();
//				return super.onKeyDown(keyCode, event);
			}
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
